package ro.jproject.imc.view;



import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import ro.jproject.imc.model.DataBaseConnection;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;




public class Ums extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;

	/**
	 * Create the frame.
	 */
	public Ums() {
		setTitle("UMS");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500, 200, 600, 308);
	
		
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new GridLayout(1, 0, 0, 0));

		JPanel panel = new JPanel();
		contentPane.add(panel);

		JLabel students = new JLabel("Students");
		students.setBounds(75, 9, 83, 14);

		JLabel profesors = new JLabel("Profesors");
		profesors.setBounds(261, 9, 83, 14);

		JButton showStudentsDataBase = new JButton("Show students");
		showStudentsDataBase.setBounds(23, 37, 151, 31);
		showStudentsDataBase.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DataBaseConnection showDataBase = new DataBaseConnection();
				showDataBase.connected();
				try {
					showDataBase.queryE();

				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				setVisible(false);
			}
		});

		JButton showProfesorsDataBase = new JButton("Show professors");
		showProfesorsDataBase.setBounds(214, 37, 151, 31);
		showProfesorsDataBase.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent E) {
				DataBaseConnection showDataBase = new DataBaseConnection();
				showDataBase.connected();
				try {
					showDataBase.queryShowProfessorsDataBase();

				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				setVisible(false);
			}
		});

		JButton addNewStudent = new JButton("Add new student");
		addNewStudent.setBounds(23, 93, 151, 31);
		addNewStudent.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AddStudentGUI showAddUserIterf = new AddStudentGUI();
				showAddUserIterf.setVisible(true);
				setVisible(false);
			}
		});

	JButton addNewProfessor = new JButton("Add new professor");
	addNewProfessor.setBounds(214, 93, 151, 31);
		addNewProfessor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AddProfessorGUI addProfesor = new AddProfessorGUI();
				addProfesor.setVisible(true);
				setVisible(false);
			}
		});

		JButton exit = new JButton("Exit");
		exit.setBounds(214, 214, 151, 31);
		exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		
		JButton showUniversityDataBase = new JButton("Show university");
		showUniversityDataBase.setBounds(395, 37, 151, 31);
		showUniversityDataBase.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DataBaseConnection showDataBase = new DataBaseConnection();
				showDataBase.connected();
				try {
					showDataBase.queryShowUniversityDataBase();

				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				ShowUniversityDataBase showUniversityDataBase = new ShowUniversityDataBase();
				showUniversityDataBase.setVisible(true);
				setVisible(false);
			}
		});
		
		JButton btnAddNewFaculty = new JButton("Add new university");
		btnAddNewFaculty.setBounds(395, 93, 151, 31);
		btnAddNewFaculty.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AddFacultyGUI showAddUserIterf = new AddFacultyGUI();
				showAddUserIterf.setVisible(true);
				setVisible(false);
			}
		});
		
		JLabel lblUniversity = new JLabel("University");
		lblUniversity.setBounds(442, 9, 83, 14);
		panel.setLayout(null);
		panel.add(showStudentsDataBase);
		panel.add(addNewStudent);
		panel.add(students);
		panel.add(profesors);
		panel.add(showProfesorsDataBase);
		panel.add(addNewProfessor);
		panel.add(btnAddNewFaculty);
		panel.add(showUniversityDataBase);
		panel.add(lblUniversity);
		panel.add(exit);
		
		JButton btnUpdateStudent = new JButton("Update students");
		btnUpdateStudent.setBounds(23, 93, 151, 31);
		btnUpdateStudent.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			
				
				DataBaseConnection showDataBase = new DataBaseConnection();
				showDataBase.connected();
				try {
					
					showDataBase.queryUpdate();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				UpdateStudentsDataBase updateDataBase = new UpdateStudentsDataBase();
				updateDataBase.setVisible(true);
				setVisible(false);

			}
		});
		
		btnUpdateStudent.setBounds(23, 143, 151, 31);
		panel.add(btnUpdateStudent);
		
		JButton btnUpdateProfessors = new JButton("Update professors");
		btnUpdateProfessors.setBounds(214, 143, 151, 31);
		panel.add(btnUpdateProfessors);
		
		JButton btnUpdateUniversity = new JButton("Update university");
		btnUpdateUniversity.setBounds(395, 143, 151, 31);
		panel.add(btnUpdateUniversity);
	}
}
